package escom.dds.gestionarcarrera.controller;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import escom.dds.gestionarcarrera.bussines.CarreraBs;
import escom.dds.modelo.Carrera;

public class GestionarCarreraCtrl extends ActionSupport implements
		ModelDriven<Carrera> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Carrera model;

	private CarreraBs carreraBs;

	private Integer idSel;

	private List<Carrera> listCarreras;

	public String index() {
		listCarreras = carreraBs.findAll();
		return "index";
	}

	public String editNew() {
		return "editNew";
	}

	public String create() {
		carreraBs.save(model);
		return index();
	}

	public String edit() {
		return "edit";
	}

	public String update() {
		carreraBs.update(model);
		return index();
	}

	public String deleteConfirm() {
		return "deleteConfirm";
	}

	public String destroy() {
		System.out.println("destroyyyy");
		carreraBs.delete(model);
		return index();
	}

	/**
	 * @return the carreraBs
	 */
	public CarreraBs getCarreraBs() {
		return carreraBs;
	}

	/**
	 * @param carreraBs
	 *            the carreraBs to set
	 */
	public void setCarreraBs(CarreraBs carreraBs) {
		this.carreraBs = carreraBs;
	}

	/**
	 * @return the idSel
	 */
	public Integer getIdSel() {
		return idSel;
	}

	/**
	 * @param idSel
	 *            the idSel to set
	 */
	public void setIdSel(Integer idSel) {
		this.idSel = idSel;
		model = new Carrera();
		if (idSel != null) {
			model.setId(idSel);
			model = carreraBs.findById(model);
		}
	}

	/**
	 * @return the listCarreras
	 */
	public List<Carrera> getListCarreras() {
		return listCarreras;
	}

	/**
	 * @param listCarreras
	 *            the listCarreras to set
	 */
	public void setListCarreras(List<Carrera> listCarreras) {
		this.listCarreras = listCarreras;
	}

	/**
	 * @return the model
	 */
	public Carrera getModel() {
		return model;
	}

	/**
	 * @param model
	 *            the model to set
	 */
	public void setModel(Carrera model) {
		this.model = model;
	}

}
